import {Injectable} from '@angular/core';
import {CanActivate} from '@angular/router';
import {UtilService} from "../my-service/util.service";
import {UserGuidState} from "../app.state";
import {Select} from '@ngxs/store';
import {Observable} from 'rxjs';

@Injectable()
export class EnterGuard implements CanActivate {
  @Select(UserGuidState) userGuid$: Observable<any>; //获取用户guid和登录状态
  login:boolean;
  constructor(private utilService: UtilService) {
  }

  canActivate(): any {
    return this.utilService.getUserInfo().then(res=>{
      if(res.userGuid){
        return true
      }else {
        return false;
      }
    })
  }

}
